package com.lpit.crawler;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.List;

@Data
@Configuration
@PropertySource("classpath:crawler.properties")//地址
@ConfigurationProperties(prefix = "crawler.init.url")
public class CrawlerConfig {

    private String prefix;
    private String suffix;

    public List<String> getInitCrawlerUrlList() {
        List<String> listCrawlerUrl = new ArrayList<>();
        if (StringUtils.isNotEmpty(suffix)) {
            String[] split = suffix.split(",");
            if (split.length > 0) {
                for (String s : split) {
                    if (!s.toLowerCase().startsWith("http")) {
                        listCrawlerUrl.add(prefix + s);
                    }
                }
            }
        }
        return listCrawlerUrl;
    }

    @Bean
    public SeleniumClient getSeleniumClient() {
        return new SeleniumClient();
    }

    @Bean
    public RestTemplate getRestTemplate(){
        return new RestTemplate();
    }

}


